<?php
/**
 * Created by PhpStorm.
 * User: ming
 * Date: 17-8-17
 * Time: 上午9:57
 */
$workers=[];
$workers_num=3;

for ($i=0;$i<$workers_num;$i++){
    $process=new swoole_process('doProcess');
    $pid=$process->start();
    $workers[$pid]=$process;
}

function doProcess(swoole_process $process){
    $process->write("PID: $process->pid");
    echo  "写入信息到管道：$process->pid $process->callback \n";
}

foreach ($workers as $process){
    swoole_event_add($process->pipe,function ($pipe) use ($process){
       $data=$process->read();//读取管道数据
        echo "接收到：$data \n";
    });
}